from chapter02.SmallStepSemantic.Add import Add
from chapter02.SmallStepSemantic.Assign import Assign
from chapter02.SmallStepSemantic.Machine import Machine
from chapter02.SmallStepSemantic.Number import Number
from chapter02.SmallStepSemantic.Variable import Variable
from chapter02.SmallStepSemantic.While import While
from chapter02.SmallStepSemantic.LessThan import LessThan
from chapter02.SmallStepSemantic.DoNothing import DoNothing
from chapter02.SmallStepSemantic.Sequence import Sequence

# x = x + 1 

# Machine(
#     Assign('x', Add(Variable('x'), Number(1))),
#     {'x': Number(2)}
# ).run()

# 计算 0-9 的和
# sum = 0 
# i = 0
# while i < 10
#     sum = sum + i
#     i = i + 1

Machine( 
        Sequence(While(LessThan(Variable("i"),Number(10)),
                        Sequence(Assign("sum",Add(Variable("sum"),Variable("i"))),
                                 Assign("i",Add(Variable("i"),Number(1))),                                          
                                )
                      ),
                DoNothing()
                )
            ,{'sum':Number(0),'i':Number(0)}
).run()

print('')
